namespace SimpleWebServices.Configuration
{
    using System.Xml.XPath;
    using SimpleWebServices;
    using Xunit;

    public sealed class TestingSettingsFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<TestingSettings>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("testing")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            TestingSettings actual = (
                "<testing>" +
                    "<http>" +
                        "<headers>" +
                            "<absent>Server</absent>" +
                            "<absent>X-Powered-By</absent>" +
                        "</headers>" +
                    "</http>" +
                "</testing>").Deserialize<TestingSettings>();

            Assert.NotNull(actual);

            Assert.NotEmpty(actual.Http.Headers.Absent);
        }

        [Fact]
        public void deserializeEmpty()
        {
            TestingSettings actual = "<testing />".Deserialize<TestingSettings>();

            Assert.NotNull(actual);

            Assert.Empty(actual.Http.Headers.Absent);
        }

        [Fact]
        public void serialize()
        {
            TestingSettings obj = new TestingSettings
            {
                Http =
                {
                    Headers =
                    {
                        Absent =
                        {
                            "Server",
                            "X-Powered-By"
                        }
                    }
                }
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("2=count(/testing/http/headers/absent[text()])"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new TestingSettings());
        }

        [Fact]
        public void prop_Http()
        {
            Assert.True(new PropertyExpectations(typeof(TestingSettings).GetProperty("Http"))
                .XmlElement("http")
                .TypeIs<HttpSettings>()
                .DefaultValueIsNotNull()
                .Result);
        }
    }
}